home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / src_1218.zip / SLHCDUMP.C < prev    next >
C/C++ Source or Header  |  1991-09-18  |  3KB  |  121 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "ip.h"
  6. #include "slhc.h"
  7. #include "trace.h"
  8.  
  9. static int16 decodeint __ARGS((struct mbuf **bpp));
  10.  
  11. static int16
  12. decodeint(bpp)
  13. struct mbuf **bpp;
  14. {
  15.     char tmpbuf[2];
  16.  
  17.     pullup(bpp,tmpbuf,1);
  18.     if (tmpbuf[0] == 0)
  19.         pullup(bpp,tmpbuf,2);
  20.     else {
  21.          tmpbuf[1] = tmpbuf[0];
  22.         tmpbuf[0] = 0;
  23.     }
  24.     return(get16(tmpbuf));
  25. }
  26.  
  27. void
  28. vjcomp_dump(fp,bpp,unused)
  29. FILE *fp;
  30. struct mbuf **bpp;
  31. int unused;
  32. {
  33.     char changes;
  34.     char tmpbuf[2];
  35.  
  36.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  37.         return;    
  38.  
  39.     /* Dump compressed TCP/IP header */
  40.     changes = pullchar(bpp);
  41.     fprintf(fp,"\tchanges: 0x%02x",uchar(changes));
  42.     if (changes & NEW_C) {
  43.         pullup(bpp,tmpbuf,1);
  44.         fprintf(fp,"   connection: 0x%02x",uchar(tmpbuf[0]));
  45.     }
  46.     pullup(bpp,tmpbuf,2);
  47.     fprintf(fp,"   TCP checksum: 0x%04x",get16(tmpbuf));
  48.  
  49.     if (changes & TCP_PUSH_BIT)
  50.         fprintf(fp,"   PUSH");
  51.     fprintf(fp,"\n");
  52.  
  53.     switch (changes & SPECIALS_MASK) {
  54.     case SPECIAL_I:
  55.         fprintf(fp,"\tdelta ACK and delta SEQ implied by length of data\n");
  56.         break;
  57.  
  58.     case SPECIAL_D:
  59.         fprintf(fp,"\tdelta SEQ implied by length of data\n");
  60.         break;
  61.  
  62.     default:
  63.         if (changes & NEW_U) {
  64.             fprintf(fp,"\tUrgent pointer: 0x%02x",decodeint(bpp));
  65.         }
  66.         if (changes & NEW_W)
  67.             fprintf(fp,"\tdelta WINDOW: 0x%02x",decodeint(bpp));
  68.         if (changes & NEW_A)
  69.             fprintf(fp,"\tdelta ACK: 0x%02x",decodeint(bpp));
  70.         if (changes & NEW_S)
  71.             fprintf(fp,"\tdelta SEQ: 0x%02x",decodeint(bpp));
  72.         break;
  73.     };
  74.     if (changes & NEW_I) {
  75.         fprintf(fp,"\tdelta ID: 0x%02x\n",decodeint(bpp));
  76.     } else {
  77.         fprintf(fp,"\tincrement ID\n");
  78.     }
  79. }
  80.  
  81.  
  82. /* dump serial line IP packet; may have Van Jacobson TCP header compression */
  83. void
  84. sl_dump(fp,bpp,unused)
  85. FILE *fp;
  86. struct mbuf **bpp;
  87. int unused;
  88. {
  89.     struct mbuf *bp, *tbp;
  90.     unsigned char c;
  91.     int len;
  92.  
  93.     bp = *bpp;
  94.     c = bp->data[0];
  95.     if (c & SL_TYPE_COMPRESSED_TCP) {
  96.         fprintf(fp,"serial line VJ Compressed TCP: len %3u\n",
  97.             len_p(*bpp));
  98.         vjcomp_dump(fp,bpp,0);
  99.     } else if ( c >= SL_TYPE_UNCOMPRESSED_TCP ) {
  100.         fprintf(fp,"serial line VJ Uncompressed TCP: len %3u\n",
  101.             len = len_p(bp));
  102.         /* Get our own copy so we can mess with the data */
  103.         if ( (tbp = copy_p(bp, len)) == NULLBUF )
  104.             return;
  105.  
  106.         fprintf(fp,"\tconnection ID = %d\n",
  107.             uchar(tbp->data[9]));    /* FIX THIS! */
  108.         /* Restore the bytes used with Uncompressed TCP */
  109.         tbp->data[0] &= 0x4f;        /* FIX THIS! */
  110.         tbp->data[9] = TCP_PTCL;    /* FIX THIS! */    
  111.         /* Dump contents as a regular IP packet */
  112.         ip_dump(fp,&tbp,1);
  113.         free_p(tbp);
  114.     } else {
  115.         fprintf(fp,"serial line IP: len: %3u\n",len_p(*bpp));
  116.         ip_dump(fp,bpp,1);
  117.     }
  118. }
  119.  
  120.  
  121.